package com.ztt.vxchat.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.cron.CronUtil;
import com.ztt.vxchat.utils.ToolsUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ztt
 * @project_name vx-chat
 * @description []
 * @date 2022/8/24 22:09
 */
@Controller
public class ViewController {

    @RequestMapping(value = {"/","/index"})
    public Object index(Model m){


        String vxConfigPath = ToolsUtil.getNowProjectPath()+"/vx-config.json";
        String messagePath = ToolsUtil.getNowProjectPath()+"/message.json";
        String tokenPath = ToolsUtil.getNowProjectPath()+"/access-token.json";

        String vxConfigStr = "";
        String messageStr = "";
        String tokenStr = "";

        FileReader vxConfigFile = null;
        try {
            vxConfigFile= new FileReader(vxConfigPath);
            vxConfigStr = vxConfigFile.readString();
        }catch (IORuntimeException e) {
            vxConfigStr = "文件不存在，请先初始化";
        }

        FileReader messageFile = null;
        try {
            messageFile= new FileReader(messagePath);
            messageStr = messageFile.readString();
        }catch (IORuntimeException e) {
            messageStr = "文件不存在，请先初始化";
        }

        FileReader tokenFile = null;
        try {
            tokenFile= new FileReader(tokenPath);
            tokenStr = tokenFile.readString();
        }catch (IORuntimeException e) {
            tokenStr = "文件不存在，请先初始化";
        }

        m.addAttribute("vxConfig",vxConfigStr);
        m.addAttribute("messageConfig",messageStr);
        m.addAttribute("tokenConfig",tokenStr);
        return "index";
    }




    @RequestMapping(value = {"/var"})
    public Object var(Model m){
        return "var";
    }




}
